package com.xuexi.springcloud.controller;

import com.xuexi.springcloud.pego.Dept;
import com.xuexi.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptConsumerController {
    @Autowired
    private DeptClientService service=null;
// 这里是消费者，就不需要有service层了
//    RestTemplate 直接调用
//    @Autowired
//    private RestTemplate restTemplate;
//    当负载均衡时，这个就不能写死了，需要是变量
//    private static final String REST_URL_QIAN = "http://localhost:8001";
//    这是负载均衡时的，通过提供者的ip
//    private static final String REST_URL_QIAN = "http://springcloud-provider-dept";
    @GetMapping("/consumer/dept/get/{id}")
    public Dept get(@PathVariable("id") Long id){
        return this.service.queryByIde(id);
    }
    @GetMapping("/consumer/dept/add")
    public boolean add(Dept dept){
        return this.service.addDept(dept);
    }
    @GetMapping("/consumer/dept/list")
    public List<Dept> list(){
        return this.service.queryAll();
    }
}
